var $;
var table;
var form
layui.use(['jquery', 'table', 'layer', 'laydate', 'form'], function () {
    $ = layui.jquery;
    table = layui.table;
    form = layui.form;
})
/*获取用户信息*/
grade = function grade(userId){
    localStorage.setItem("gradeId",userId);
    $.ajax({
        type: "post",
        dataType: "json",
        data: {"id": userId},
        url: "/newJurisdiction/getUserPower",
        success: function (data) {
            editUserPower(data);
        }
    })
}
/*操作权限*/
updateGrade = function updateGrade(type){
    var id = localStorage.getItem("gradeId");
    var gradeIds;
    if(type==1){
        gradeIds = "#guan";
    }else if(type==2){
        gradeIds = "#teacher";
    }else if(type==3){
        gradeIds = "#shop";
    }else if(type==4){
        gradeIds = "#people";
    }
    console.log($(gradeIds).val());
    if($(gradeIds).val()=="1"){
        $(gradeIds).val("2");
        var json ={
            "userId":id,
            "authorityId":type
        }
        $.ajax({
            type: "post",
            dataType: "json",
            data: json,
            url: "/newJurisdiction/delUserGrade",
            success: function (data) {
                console.log(data);
                if(data.data){
                    alert("当前权限已关闭");
                }else {
                    alert("服务器错误");
                }
            }
        })
    }else{
        $(gradeIds).val("1");
        var json ={
            "userId":id,
            "authorityId":type,
            "type":2,
            "createId":id,
            "createDate":getTime(new Date())
        }
        $.ajax({
            type: "post",
            dataType: "json",
            data: json,
            url: "/newJurisdiction/addUserGrade",
            success: function (data) {
                console.log(data);
                if(data.data){
                    alert("当前权限已开启");
                }else {
                    alert("服务器错误");
                }
            }
        })
    }
}
/*完成*/
wanCheng = function wanCheng() {
    var index  = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

/*获取一个当前时间*/
function getTime(date){
    var year = date.getFullYear(); //获取完整的年份(4位,1970-????)
    var month = date.getMonth()+1; //获取当前月份(0-11,0代表1月)
    var today = date.getDate(); //获取当前日(1-31)
    var hour = date.getHours(); //获取当前小时数(0-23)
    var minute = date.getMinutes(); //获取当前分钟数(0-59)
    var second = date.getSeconds(); //获取当前秒数(0-59)
    var nowTime;
    nowTime = year+'-'+fillZero(month)+'-'+fillZero(today)+' '+fillZero(hour)+':'+fillZero(minute)+':'+fillZero(second);
    return nowTime;
};
/*补全单位时间*/
function fillZero(str){
    var realNum;
    if(str<10){
        realNum	= '0'+str;
    }else{
        realNum	= str;
    }
    return realNum;
};